package com.caozhen.manage.util;

import java.util.ArrayList;
import java.util.List;
 

/**
 * 分页
 * @author cao
 *
 * @param <T>
 */
public class PageResponse<T> {
	private int page;
	private int pageSize;
	private int total;//总数
	private List<T> content = new ArrayList<T>();
	
	/**  
	 * 获取  page  
	 * @return page 
	 */
	public int getPage() {
		return page;
	}
	/**  
	 * 设置  page  
	 * @param page 
	 */
	public void setPage(int page) {
		this.page = page;
	}
	/**  
	 * 获取  pageSize  
	 * @return pageSize 
	 */
	public int getPageSize() {
		return pageSize;
	}
	/**  
	 * 设置  pageSize  
	 * @param pageSize 
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	
	public PageResponse(int page, int pageSize, int total, List<T> content) {
		super();
		this.page = page;
		this.pageSize = pageSize;
		this.total = total;
		this.content = content;
	}
	 
	/**  
	 * 获取  total  
	 * @return total 
	 */
	public int getTotal() {
		return total;
	}
	/**  
	 * 设置  total  
	 * @param total 
	 */
	public void setTotal(int total) {
		this.total = total;
	}
	
	public List<T> getContent() {
		return content;
	}
	public void setContent(List<T> content) {
		this.content = content;
	}
	public int getCurrentPage(){
		if(page == 0){
			return 1;
		}
		return page;
	}
	
	public int getTotalPage() {
		int pageSize = getPageSize();
		if(pageSize==0){
			return 0;
		}
		Double result = Math.ceil(((double)total/pageSize));
		return result.intValue();
	}
	
	public int getOffset() {
		if(page>0){
			return (page - 1) * pageSize;
		}
		return 0;
	}
	
}
